package com.global.emc.spring.exception.handler.emcexception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.web.method.HandlerMethod;

import com.global.emc.core.CoreUser;
import com.global.emc.core.exception.IEMCException;
import com.global.emc.spring.exception.handler.SpringMVCEMCExceptionHandler;

/**   
 *  
 * @Description:  [处理错误日志]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年2月20日 下午5:01:53]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年2月20日 下午5:01:53]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public abstract class LoggerEMCExceptionHandler extends ApplicationObjectSupport implements SpringMVCEMCExceptionHandler{


	/**
	 * 返回错误日志
	 * @param request
	 * @param exception
	 * @param handlerMethod
	 * @return
	 */
	public String exceptionLog(HttpServletRequest request, IEMCException emcException, Object handlerMethod) {
		CoreUser coreUser = (CoreUser) request.getSession().getAttribute(CoreUser.CORE_USER);
		String uniqueId = (coreUser == null ? "NOUSER" : coreUser.getUniqueId());
		StringBuffer exceptionLog = new StringBuffer("TrsError========>");
		exceptionLog.append(" UserId:").append(uniqueId);
		exceptionLog.append(" Message:").append(emcException.getMessage());
		exceptionLog.append(" LocalizedMessage:").append(emcException.getLocalizedMessage());
		if (null != handlerMethod)
			exceptionLog.append(" HandlerMethod:").append(
					((HandlerMethod) handlerMethod).getMethod());
		exceptionLog.append(" ThreadId:")
				.append(Thread.currentThread().getId());

		return exceptionLog.toString();
	}

}
